import React, {PureComponent} from 'react';
import styles from './index.less';
import {Table, Alert, Badge, Switch, Icon, InputNumber, Tooltip, Popconfirm,Button}  from 'antd';
import {powerControl} from '../../utils/powerControl';
const AuthButton = powerControl(Button);

class SystemPermissionList extends PureComponent {

    state = {
        selectedRowKeys: [],
        totalCallNo: 0,
    };
    componentWillReceiveProps(nextProps) {
        if (nextProps.selectedRows.length === 0) {
            this.setState({
                selectedRowKeys: [],
                totalCallNo: 0,
            });
        }
    }
    handleEditRow = (record, pagination) => {
        this.props.onEditRow(record, pagination);
    }

    handleTableChange = (pagination, filters, sorter) => {
        this.props.onChange(pagination, filters, sorter);
    }

    handleDelRow = (systemPermissionList_id, pagination) => {
        this.props.onDelRow(systemPermissionList_id, pagination);
    }
    /*
     * */
    render(){
        const {selectedRowKeys, totalCallNo} = this.state;
        const {data: {list, pagination}, loading} = this.props;
        const columns = [
            {
                title: '系统权限编码', dataIndex: 'ACTION_CODE',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.ACTION_CODE}>
                        <span>{val}</span>
                    </Tooltip>
                }
            },
            {
                title: '系统权限描述', dataIndex: 'ACTION_DESC',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.ACTION_DESC}>
                        <span>{val}</span>
                    </Tooltip>
                }
            },
            {
                title: '系统权限类型', dataIndex: 'action_type',
                render: (val, record) => {
                    return <Tooltip placement="right" title={record.action_type === 0?"平台权限":"商家权限"}>
                        <span >{record.action_type === 0 ? "平台权限":"商家权限"}</span>
                    </Tooltip>
                }
            },
            {
                title: '操作',
                // fixed: 'right',
                render: (val, record) => (
                    <p>
                        <AuthButton auth="sysPermissionList.edit"  ghost  className={styles.btn} size="small" onClick={() => this.handleEditRow(record, pagination)}>编辑</AuthButton>
                        <span className={styles.splitLine}/>
                        <Popconfirm title="是否确定删除?" onConfirm={() => this.handleDelRow(record.ACTION_ID, pagination)} >
                            <AuthButton  ghost  className={styles.btn} size="small"   auth="sysPermissionList.delete">删除</AuthButton>
                        </Popconfirm>
                    </p>
                ),
            },
        ];

        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
                console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
            },
            onSelect: (record, selected, selectedRows) => {
                console.log(record, selected, selectedRows);
            },
            onSelectAll: (selected, selectedRows, changeRows) => {
                console.log(selected, selectedRows, changeRows);
            },
        };
        const paginationProps = {
            showSizeChanger: true,
            showQuickJumper: true,
            ...pagination,
        };
        return (
            <div className={styles.standardTable}>
                <Table
                    loading={loading}
                    rowKey={record => record.action_id}
                    rowSelection={rowSelection}
                    dataSource={list}
                    columns={columns}
                    pagination={paginationProps}
                    onChange={this.handleTableChange}
                    scroll={{x: 1000}}
                />
            </div>
        )

    }
}
export default SystemPermissionList;

